package com.xipu.yygh.cmn.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.xipu.yygh.cmn.mapper.DictMapper;
import com.xipu.yygh.model.cmn.Dict;
import com.xipu.yygh.vo.cmn.DictEeVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * description: 数据字典上传监听器
 * @author: gql
 * @date: 2022/04
 */
@Component
public class DictListener extends AnalysisEventListener<DictEeVo> {

    @Autowired
    private DictMapper dictMapper;

    /**
     * 从第二行开始,一行一行读内容,并添加到数据库
     * @param dictEeVo 每行数据
     * @param context 监听器环境
     */
    @Override
    public void invoke(DictEeVo dictEeVo, AnalysisContext context) {
        Dict dict = new Dict();
        BeanUtils.copyProperties(dictEeVo, dict);
        dictMapper.insert(dict);
    }

    /**
     * if have something to do after all analysis
     *
     * @param context 监听器环境
     */
    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {

    }
}
